import { Handler, NextFunction } from 'express';
import * as jwt from './jwt';
const loginURL = new Set();
loginURL.add("/api/pc/login");
loginURL.add("/api/pc/register");
loginURL.add("/api/pc/is-pass-register");
loginURL.add("/api/mob/login-school");

const fn: Handler = function (req, _res, next) {
    if (loginURL.has(req.url.split("?")[0])) {
        
        next();
    } else {
        if (req.headers.token) {
            
            jwt.vaild(req.headers.token.toString())
                .then(res => {
                    (req as any).token = res;
                    next();
                }).catch(res => {
                    _res.send({
                        status: 1,
                        msg: "用户token验证失败"
                    })
                    // _res.send({state:false})
                })
        } else {
            _res.send({
                status: 1,
                msg: "用户未登录"
            })
        }
    }
}
export default fn;